#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

//书架
std::vector<std::string> shelves[10010];
int main() {
    //n是书架的数量，m是书的数量以及m次操作
    int n, m;
    std::cin >> n >> m;

    //m次操作
    for (int i = 0; i < m; i++) {
        int shelfIdx;
        std::string bookName;

        std::cin >> shelfIdx >> bookName;

        shelves[shelfIdx].push_back(bookName);

    }


    for (int shelfIdx = 1; shelfIdx <= n; shelfIdx++) {
        std::cout << shelfIdx << " ";
        std::cout << shelves[shelfIdx].size() << " ";

        std::sort(shelves[shelfIdx].begin(), shelves[shelfIdx].end());

        for (int j=0; j < shelves[shelfIdx].size(); j++) {
            std::cout << shelves[shelfIdx][j] << " ";
        }

        std::cout << "\n";

    }

    return 0;
}